package com.hgh.model;

import com.misakubex.Main;

/**
 * @author Administrator
 */
public class Tank {

    private int x;
    private int y;
    public  int size = Main.a;
    private char dirct;
    public int speed = Main.a;
    /**
     * 是否敌机，敌机则该值为true
     */
    private boolean enemy=false;
    /**
     * 可发射的子弹的数量
     */
    private int missileNum=2;

    public Tank() {
    }

    public void setX(int x) {
        this.x=x;
    }

    public void setY(int y) {
        this.y=y;
    }

    public void moveUp(){
        if(y>0) {
            if(Map.points[x/Main.a][(y-speed)/Main.a]!=Map.REDWALL&&Map.points[x/Main.a][(y-speed)/Main.a]!=Map.WHITEWALL){
            this.setY(this.getY()-speed);
        }}
    }

    public void moveDown(){
        if(y<=Main.a*24) {
            if(Map.points[x/Main.a][(y+speed)/Main.a]!=Map.REDWALL&&Map.points[x/Main.a][(y+speed)/Main.a]!=Map.WHITEWALL)
            {
                this.setY(this.getY()+speed);
            }
        }
    }

    public void moveLeft(){
        if(x>0) {
            if(Map.points[(x-speed)/Main.a][y/Main.a]!=Map.REDWALL&&Map.points[(x-speed)/Main.a][y/Main.a]!=Map.WHITEWALL){
                this.setX(this.getX()-speed);
            }
        }
    }

    public void moveRight(){
        if(x<=Main.a*24) {
            if(Map.points[(x+speed)/Main.a][y/Main.a]!=Map.REDWALL&&Map.points[(x+speed)/Main.a][y/Main.a]!=Map.WHITEWALL){
                this.setX(this.getX()+speed);
        }}
    }

    /**
     * 坦克的可发射子弹加1
     * @param tank
     */
    public static void addMissileNum(Tank tank){
        tank.missileNum = tank.missileNum + 1;
    }

    /**
     * 发射子弹
     */
    public Missile emissionMissile(){
        if(this.missileNum>0){
            this.missileNum -=1;
            Missile missile = new Missile(this);
            return missile;
        }
        else{
            return null;
        }
    }

    public void setDirect(char dirct) {
        this.dirct=dirct;
    }


    public void setSpeed(int speed) {
        this.speed = speed;
    }
    public int getSpeed() {
        return this.speed;
    }

    public int getMissileNum() {
        return missileNum;
    }

    public void setMissileNum(int missileNum) {
        this.missileNum = missileNum;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public boolean isEnemy() {
        return enemy;
    }

    public void setEnemy(boolean enemy) {
        this.enemy = enemy;
    }

    public char getDirct() {
        return dirct;
    }

    public void setDirct(char dirct) {
        this.dirct = dirct;
    }
}